package com.laozhao.deliveryManager.test;

import javax.swing.*;
import java.awt.*;

public class GridBagLayout1{

    public GridBagLayout1() {
        super();

    }

    public static void main(String[] args) {
        GridBagFrame gf = new GridBagFrame();
        gf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gf.setVisible(true);

    }

}

class GridBagFrame extends JFrame {
    GridBagFrame() {
        setTitle("Hello GridBagLayout");
        setSize(400, 200);
        Container c = getContentPane();
        GridBagPanel g = new GridBagPanel();
        c.add(g);

    }

}

class GridBagPanel extends JPanel {
    GridBagPanel() {
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();

        setFont(new Font("SansSerif", Font.PLAIN, 14));
       
        setLayout(gridbag);

        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        makebutton("Button1", gridbag, c);
        makebutton("Button2", gridbag, c);
        makebutton("Button3", gridbag, c);

        c.gridwidth = GridBagConstraints.REMAINDER; // end row
        makebutton("Button4", gridbag, c);

        c.weightx = 0.0; // reset to the default
        makebutton("Button5", gridbag, c); // another row

        c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last in row
        makebutton("Button6", gridbag, c);

        c.gridwidth = GridBagConstraints.REMAINDER; // end row
        makebutton("Button7", gridbag, c);

        c.gridwidth = 1; // reset to the default
        c.gridheight = 2;
        c.weighty = 1.0;
        makebutton("Button8", gridbag, c);

        c.weighty = 0.0; // reset to the default
        c.gridwidth = GridBagConstraints.REMAINDER; // end row
        c.gridheight = 1; // reset to the default
        makebutton("Button9", gridbag, c);
        makebutton("Button10", gridbag, c);

    }
    protected void makebutton(String name, GridBagLayout gridbag,
            GridBagConstraints c) {
        Button button = new Button(name);
        gridbag.setConstraints(button, c);
        add(button);
    }
}